package com.leyou.cart.web;

import com.leyou.cart.pojo.Cart;
import com.leyou.cart.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author 虎哥
 */
@RestController
public class CartController {

    @Autowired
    private CartService cartService;

    /**
     * 新增购物车
     * @param cart 购物车数据
     * @return 无
     */
    @PostMapping
    public ResponseEntity<Void> saveCart(@RequestBody Cart cart){
        cartService.saveCart(cart);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    @GetMapping("list")
    public ResponseEntity<List<Cart>> queryCartList(){
        return ResponseEntity.ok(cartService.queryCartList());
    }

    /**
     * 修改购物车数量
     * @param cart 购物车数据
     * @return 无
     */
    @PutMapping
    public ResponseEntity<Void> updateCart(@RequestBody Cart cart, HttpServletRequest request){

        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }
}
